package com.mfz.common.dbHelper

import org.apache.logging.log4j.LogManager
import org.junit.Test
import java.util.*
import kotlin.collections.ArrayList

internal val log = LogManager.getLogger(DBTest::class.java.name)

class DBTest {


	@Test
	fun testDB() {
		val list = ArrayList<Thread>()
		for (i in 1..200) {
			val t = Thread {
				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)

				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)
				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)
				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)
				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)
				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)
				dbHelper.query("select * from user_info where id = 662;") {
					log.trace("得到的值，row :${it.getObject(1)}")
				}
				dbHelper.close(closeThread = true)
				Thread.sleep(Random().nextInt(500 + 1 - 60).toLong() + 60)
			}

			list.add(t)
			t.start()
		}

		for (t in list) {
			t.join()
		}
	}


}